//
//  MainViewController.m
//  穷游项目
//
//  Created by 刘建镇 on 14-12-29.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "macro.h"
#import "Masonry.h"
#import "MainViewController.h"
#import "ButtonModel.h"
#import "TravelTopicTableViewCell.h"
#import "Beauty_PicViewController.h"
#import "AroundPeopleViewControllers.h"
#import "ExtraButton.h"
#import "Singleton.h"
#import "UIImageView+WebCache.h"
#import "UIScrollView+PullLoad.h"
#import "MicroDetailViewController.h"
#import "TravelTopicViewController.h"
#import "ADViewController.h"
#import "sinaWiboViewController.h"
#import "LoginViewCnntroller.h"
#import "WebColor.h"
#import "AFJSONRequestOperation.h"
#import "UIImageView+WebCache.h"


@interface MainViewController ()<UITableViewDataSource, UITableViewDelegate, PullDelegate, UIGestureRecognizerDelegate, UIScrollViewDelegate, UIAlertViewDelegate>

@end

@implementation MainViewController

- (void)dealloc
{
    [_table release];
    [_headView release];
    [_headScroll release];
    [_page release];
    [_myTimer release];
    [_buttonScr release];
    [_label1 release];
    [_label2 release];
    [_label3 release];
    [_label4 release];
    [_button release];
    [_photoArray release];
    [_slideArray release];
    [_mguideArray release];
    [_tableArray release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableArray = [NSMutableArray array];
        self.slideArray = [NSMutableArray array];
        self.mguideArray = [NSMutableArray array];
        self.photoArray = [NSMutableArray array];//滑块上 存放图片的数组
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 30, self.view.frame.size.height / 2 - 90, 60, 60)];
    _imageView.image = [UIImage imageNamed:@"fireLogin.png"];
    _imageView.layer.cornerRadius = 30;
    _imageView.clipsToBounds = YES;
    [self.view addSubview:_imageView];
    
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    rotationAnimation.duration = 2;
    rotationAnimation.RepeatCount = 10000;
    rotationAnimation.cumulative = NO;
    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.fillMode = kCAFillModeBoth;
    [_imageView.layer addAnimation:rotationAnimation forKey:@"rotation"];

    // Do any additional setup after loading the view.
    if (IOS_VERSION > 7.0) {
    self.tabBarController.tabBar.translucent = NO;
    }
    self.navigationController.navigationBar.translucent = NO;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 45, 50)];
    label.text = @"哎游";
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:25.0f];
    label.textColor = [UIColor whiteColor];
    self.navigationItem.titleView =label;
    
    //音乐按钮
       
    [self creatMusicButton];
    
    
    
    [label release];
    [self json];
}

- (void) creatMusicButton
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
    self.button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
    [_button addSubview:view];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_button];
//    [_button setBackgroundColor:[WebColor mediumSeaGreen]];
    _button.backgroundColor = [UIColor clearColor];
    
    self.label1 = [[UILabel alloc] init];
    _label1.layer.cornerRadius = 2;
    _label1.clipsToBounds = YES;
    
    self.label2 = [[UILabel alloc] initWithFrame:CGRectMake(29, 2, 4, 28)];
    _label2.layer.cornerRadius = 2;
    _label2.clipsToBounds = YES;
    self.label3 = [[UILabel alloc] initWithFrame:CGRectMake(36, 12, 4, 18)];
    _label3.layer.cornerRadius = 2;
    _label3.clipsToBounds = YES;
    self.label4 = [[UILabel alloc] initWithFrame:CGRectMake(43, 7, 4, 23)];
    _label4.layer.cornerRadius = 2;
    _label4.clipsToBounds = YES;
    [_label1 setBackgroundColor:[WebColor linen]];
    [_label2 setBackgroundColor:[WebColor linen]];
    [_label3 setBackgroundColor:[WebColor linen]];
    [_label4 setBackgroundColor:[WebColor linen]];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
    button.backgroundColor = [UIColor clearColor];
    [button addTarget:self action:@selector(showPlayer:) forControlEvents:UIControlEventTouchUpInside];
    
    [view addSubview:_label1];
    [view addSubview:_label2];
    [view addSubview:_label3];
    [view addSubview:_label4];
    [view addSubview:button];
    
    [_label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(view.mas_bottom).offset(-10);
        make.right.equalTo(_label2.mas_left).offset(-3);
        make.size.mas_equalTo(CGSizeMake(4, 15));
    }];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeColor :) name:@"ANIMATION" object:nil];
    [view release];
    [button release];
    
}

- (void)showPlayer:(id)sender
{
    Singleton *share = [Singleton shareInstance];
    if ([share.musicId isEqualToString:@"-1"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前没有歌曲正在播放" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
    }else {
        [self presentViewController:share.musicPlayerViewController animated:YES completion:nil];
        share.musicPlayerViewController.playMode = MusicPlayStateOtherPlaying;
        share.musicPlayerViewController.buttonState = PlayButton;
        share.musicPlayerViewController.sameMusic = YES;
    }
}

- (void) changeColor : (NSNotification *) noti
{
    if ([[noti.userInfo objectForKey:@"state"] integerValue] == 0 || [[noti.userInfo objectForKey:@"state"] integerValue] == 3 || [noti.userInfo objectForKey:@"state"] != nil || ![[noti.userInfo objectForKey:@"state"] isEqualToString:@""]) {
        
        self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer1) userInfo:noti.userInfo repeats:NO];
        [self.myTimer setFireDate:[NSDate distantPast]];
    }else {
        [self.myTimer setFireDate:[NSDate distantFuture]];
//        [self.myTimer invalidate];
//        self.myTimer = nil;
    }
}


- (void)timer1
{
    [_label1 setBackgroundColor:[WebColor crimson]];
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer2) userInfo:nil repeats:NO];
}

- (void)timer2
{
    [_label2 setBackgroundColor:[WebColor crimson]];
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer3) userInfo:nil repeats:NO];
}

- (void)timer3
{

    [_label3 setBackgroundColor:[WebColor crimson]];
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer4) userInfo:nil repeats:NO];
}

- (void)timer4
{
    [_label4 setBackgroundColor:[WebColor crimson]];
    
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer5) userInfo:nil repeats:NO];
}

- (void)timer5
{
    [_label1 setBackgroundColor:[UIColor whiteColor]];
    
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer6) userInfo:nil repeats:NO];
}
- (void)timer6
{
    [_label2 setBackgroundColor:[UIColor whiteColor]];
    
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer7) userInfo:nil repeats:NO];
}
- (void)timer7
{
    [_label3 setBackgroundColor:[UIColor whiteColor]];
    
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timer8) userInfo:nil repeats:NO];
}
- (void)timer8
{
    [_label4 setBackgroundColor:[UIColor whiteColor]];
    
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(changeColor:) userInfo:nil repeats:NO];
}
#pragma mark - 
#pragma mark 视图的显示方法
- (void)viewWillAppear:(BOOL)animated
{
    //定时器
    self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(scrollViewTimer:) userInfo:nil repeats:YES];
    //开启定时器
    if ([_slideArray count]) {
        [_timer setFireDate:[NSDate distantPast]];
        NSLog(@"定时器开启");
    }
}

- (void)viewDidDisappear:(BOOL)animated
{
    //永久停止定时器, 取消定时器
    if (self.timer != nil){
        // 定时器调用invalidate后，就会自动执行release方法。不需要在显示的调用release方法
        [self.timer invalidate];
        _timer = nil;
//        NSLog(@"定时器取消");
    }
    //关闭定时器
//    [_timer setFireDate:[NSDate distantFuture]];
//    NSLog(@"定时器关闭");
}

- (void)scrollViewTimer:(NSTimer *)timer
{
    if ([_slideArray count]) {
        _timeCount++;
        //    NSLog(@"timecount ==== %ld", _timeCount);
        NSInteger timeChange = (_timeCount%[_slideArray count]+1);
        //    NSLog(@"timechange === %ld", timeChange);
        [_headScroll setContentOffset:CGPointMake(_headScroll.frame.size.width * timeChange, 0) animated:YES];
        self.page.currentPage = _headScroll.contentOffset.x / self.headScroll.frame.size.width;
        //    NSLog(@"self.page.currentpage === %ld", (long)self.page.currentPage);
        if (_headScroll.contentOffset.x >= self.view.frame.size.width * [_slideArray count]) {
            [_headScroll setContentOffset:CGPointMake(_headScroll.frame.size.width, 0) animated:NO];
            self.page.currentPage = 0;
        }
    }
}

#pragma mark - 
#pragma mark 数据解析
- (void)json
{
    
    //Cell解析
    NSString *strCell = @"http://api.breadtrip.com/featured/";
    NSURL *urlCell = [NSURL URLWithString:[strCell stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *requestCell = [NSURLRequest requestWithURL:urlCell];
    AFJSONRequestOperation *operationSecond = [AFJSONRequestOperation JSONRequestOperationWithRequest:requestCell success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSArray *array = [JSON objectForKey:@"elements"];
        NSDictionary *mydic = [array objectAtIndex:4];
        NSArray *arr = [mydic objectForKey:@"data"];
        [_tableArray removeAllObjects];
        for (NSDictionary *myDic in arr) {
            [_tableArray addObject:myDic];
        }
        [self createView];
        [_table reloadData];
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"发生错误了%@", error);
    }];
    [operationSecond start];
    
    //滑块广告 微锦囊解析
    
    NSString *str = @"http://open.qyer.com/qyer/recommands/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&v=1&track_user_id=&track_deviceid=215957DD-9D0B-4E5E-B913-2C45B63AAB97&track_app_version=5.4.4&track_app_channel=App%20Store&track_device_info=iPhone%204S&track_os=ios%206.1.3&lat=38.882786&lon=121.539621&app_installtime=1419661671";
    NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    AFJSONRequestOperation *operationFisrt = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        [_imageView removeFromSuperview];
        self.imageViews = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 30, self.view.frame.size.height / 2 - 30, 60, 60)];
        _imageViews.image = [UIImage imageNamed:@"fireLogin.png"];
        _imageViews.layer.cornerRadius = 30;
        _imageViews.clipsToBounds =  YES;
        [self.view addSubview:_imageViews];
        
        CABasicAnimation* rotationAnimation;
        rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
        [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        rotationAnimation.duration = 2;
        rotationAnimation.RepeatCount = 10000;
        rotationAnimation.cumulative = NO;
        rotationAnimation.removedOnCompletion = NO;
        rotationAnimation.fillMode = kCAFillModeForwards;
        [_imageViews.layer addAnimation:rotationAnimation forKey:@"rotation"];
        
        NSDictionary *mydic = [JSON objectForKey:@"data"];
        NSArray *slideArr = [mydic objectForKey:@"slide"];
        [_slideArray removeAllObjects];
        for (NSDictionary *slideDic in slideArr) {
            [self.slideArray addObject:slideDic];
            //新加的图片数组
            NSString *photo = [slideDic objectForKey:@"photo"];
            [self.photoArray addObject:photo];
        }
        id firstImage = [_photoArray firstObject];
        id lastImage = [_photoArray lastObject];
        [_photoArray insertObject:lastImage atIndex:0];
        [_photoArray addObject:firstImage];
        
        NSArray *mguideArr = [mydic objectForKey:@"mguide"];
        [_mguideArray removeAllObjects];
        for (NSDictionary *mguideDic in mguideArr) {
            [_mguideArray addObject:mguideDic];
        }
        [self addheadView];
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"发生错误!%@", error);
    }];
    [operationFisrt start];
}

#pragma mark - 
#pragma mark 循环滚动, 减速时改变偏移量
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //如果当前偏移量大于等于最后一张的那个位置的时候，改变偏移量
    if (_headScroll.contentOffset.x >= self.view.frame.size.width * ([_photoArray count] - 1)) {
        //显示用户看到的第一页
        [_headScroll setContentOffset:CGPointMake(_headScroll.frame.size.width, 0) animated:NO];
    }
    //如果当前偏移量小于等于0的时候
    if (_headScroll.contentOffset.x <= 0) {
        
        //显示用户看到的倒第二页
        [_headScroll setContentOffset:CGPointMake(_headScroll.frame.size.width * ([_photoArray count] - 2), 0) animated:NO];
    }
    self.page.currentPage = _headScroll.contentOffset.x / self.headScroll.frame.size.width - 1;
    if (_page.currentPage >= [_slideArray count]) {
        _page.currentPage = 0;
    }
    [_timer setFireDate:[NSDate distantFuture]];
}


#pragma mark - 
#pragma mark 视图的创建
- (void)addheadView
{
    //TableView的HeaderView的自定义UIView
    self.headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height * 2/3 + SCREEN_HEIGHT * 3 / 7 + SCREEN_WIDTH*2/11 + SCREEN_WIDTH/6)];
    [_headView setBackgroundColor:[WebColor aliceBlue]];
    //滑动视图
    self.headScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height * 4 / 11)];
    _headScroll.delegate = self;
    _headScroll.contentOffset = CGPointMake(_headScroll.frame.size.width, 0);
    [_headScroll setContentSize:CGSizeMake(self.view.frame.size.width * [_photoArray count], 0)];
    
    //slide赋值
    for (int i = 0; i < [_photoArray count]; i++) {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, _headScroll.frame.size.width, _headScroll.frame.size.height)];
        
        //给UIImageView添加手势点击事件//或者将UIImageView放在button上面
        UITapGestureRecognizer *singleFinger = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)];
        [imageV addGestureRecognizer:singleFinger];
        imageV.userInteractionEnabled = YES;
        singleFinger.numberOfTouchesRequired = 1; //手指数
        singleFinger.numberOfTapsRequired = 1; 
        singleFinger.delegate = self;
        //如果不加下面的话，当单指双击时，会先调用单指单击中的处理，再调用单指双击中的处理
        //        [singleFinger requireGestureRecognizerToFail:singleFingerTwo];
        [singleFinger release];

        [imageV sd_setImageWithURL:[NSURL URLWithString:[_photoArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
        singleFinger.view.tag = i + 1;//设置tag, 以便于手势点击事件
        [_headScroll addSubview:imageV];
        [imageV release];
    }
    _headScroll.pagingEnabled = YES;
    _headScroll.showsHorizontalScrollIndicator = NO;//滑块隐藏
    [_headView addSubview:_headScroll];
    
    //PageControl
    self.page = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, self.view.frame.size.height * 4 / 11 - 20, 200, 20)];
    _page.numberOfPages = [_slideArray count];
    [_headView addSubview:_page];

    //Three Button
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height * 4 / 11, self.view.frame.size.width, SCREEN_WIDTH/5)];

    [_headView addSubview:view];
    [view release];
    NSArray *array = [NSArray arrayWithObjects:@"美图", @"收藏", @"身边人", nil];
    for (int i = 0; i < 3; i++) {
        
//        if (IOS_VERSION >= 7.0) {
//            ExtraButton *button = [ExtraButton buttonWithType:UIButtonTypeRoundedRect];
//            button.frame =  CGRectMake(i * view.frame.size.width/3 + view.frame.size.width/12, 10, view.frame.size.width/6, SCREEN_WIDTH/6);
//            if (i == 0) {
//                [button addTarget:self action:@selector(beautyPicture:) forControlEvents:UIControlEventTouchUpInside];
//                if (IOS_VERSION > 7.0) {
//                    button.imageV.image = [UIImage imageNamed:@"iconfont1.png"];
//                }
//            }else if (i == 1){
//                [button addTarget:self action:@selector(myLogin:) forControlEvents:UIControlEventTouchUpInside];
//                if (IOS_VERSION > 7.0) {
//                    button.imageV.image = [UIImage imageNamed:@"iconfont-favor.png"];
//                }
//            }else if (i == 2){
//                [button addTarget:self action:@selector(aroundPeople:) forControlEvents:UIControlEventTouchUpInside];
//                if (IOS_VERSION > 7.0) {
//                    button.imageV.image = [UIImage imageNamed:@"iconfont-location.png"];
//                }
//            }
//            button.extraLabel.text = [array objectAtIndex:i];
//            [view addSubview:button];
//        }else
        {
        ExtraButton *button = [[ExtraButton alloc] initWithFrame:CGRectMake(i * view.frame.size.width/3 + view.frame.size.width/12, 10, view.frame.size.width/6, SCREEN_WIDTH/6)];
            if (i == 0) {
                [button addTarget:self action:@selector(beautyPicture:) forControlEvents:UIControlEventTouchUpInside];
                    button.imageV.image = [UIImage imageNamed:@"iconfont1.png"];
                
            }else if (i == 1){
                [button addTarget:self action:@selector(myLogin:) forControlEvents:UIControlEventTouchUpInside];
                    button.imageV.image = [UIImage imageNamed:@"iconfont-favor.png"];
                
            }else if (i == 2){
                [button addTarget:self action:@selector(aroundPeople:) forControlEvents:UIControlEventTouchUpInside];
                    button.imageV.image = [UIImage imageNamed:@"iconfont-location.png"];
            }
            button.extraLabel.text = [array objectAtIndex:i];
            [view addSubview:button];
            [button release];
        }
    }
//        button.layer.masksToBounds = YES;
//        button.layer.cornerRadius = SCREEN_WIDTH/12;
    
    //微锦囊
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, self.view.frame.size.height * 1/3 + self.view.frame.size.height/15 + SCREEN_WIDTH/5, self.view.frame.size.width/2, 20)];
    label.text = @"哎游锦囊";
    label.backgroundColor = [UIColor clearColor];
    [_headView addSubview:label];
    [label release];
    
    //微锦囊赋值
    for (int i = 0; i < [_mguideArray count]; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10 + i % 2 * (self.view.frame.size.width - 10)* 1/2, SCREEN_WIDTH/5 + SCREEN_HEIGHT * 1/3 + self.view.frame.size.height/20 + i / 2 * SCREEN_HEIGHT*3.4/11, (self.view.frame.size.width - 30) * 1/2, SCREEN_HEIGHT * 2 / 7)];
        
        [button addTarget:self action:@selector(mguideButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        ButtonModel *model = [[ButtonModel alloc] initWithFrame:CGRectMake(0, 0,(button.frame.size.width - 30) * 1/2, button.frame.size.height * 2 / 7)];
        NSDictionary *dic = [_mguideArray objectAtIndex:i];
        //id设置
        NSNumber *n = [dic objectForKey:@"id"];
        button.tag = [n integerValue];
        
        [model.imageV sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"photo"]] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
        
        model.label.text = [dic objectForKey:@"title"];
        [button addSubview:model];
        [_headView addSubview:button];
        [model release];
        [button release];
    }
    
    //今日旅游专题
    UILabel *labelTopic = [[UILabel alloc] initWithFrame:CGRectMake(10, _headView.frame.size.height - 25, self.view.frame.size.width/2, 20)];
    //今日旅游专题标题
    labelTopic.text = @"今日旅游专题";
    [_headView addSubview:labelTopic];
    [labelTopic release];
}

- (void)createView
{
    //创建tableView
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 113) style:UITableViewStylePlain];
    _table.delegate = self;
    _table.dataSource = self;
    _table.pullDelegate = self;
    _table.canPullDown = YES;
    [_table registerClass:[TravelTopicTableViewCell class] forCellReuseIdentifier:@"travelCell"];
    _table.tableHeaderView = _headView;
    [self.view addSubview:_table];
}

#pragma mark - 
#pragma mark 滑块广告的点击事件
//滑块广告的点击事件
- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender
{
    if (sender.numberOfTapsRequired == 1) {
    NSDictionary *dic = [_slideArray objectAtIndex:sender.view.tag - 2];

    ADViewController *ad = [[ADViewController alloc] init];
    ad.url = [dic objectForKey:@"url"];
    [self.navigationController pushViewController:ad animated:YES];
    [ad release];
    }
}

#pragma mark - 
#pragma mark 今日旅游专题Cell点击详情

//今日旅游专题Cell点击详情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [_tableArray objectAtIndex:indexPath.row];
    TravelTopicViewController *travelTopic = [[TravelTopicViewController alloc] init];
    travelTopic.url = [dic objectForKey:@"url"];
    [self.navigationController pushViewController:travelTopic animated:YES];
    [travelTopic release];
}

#pragma mark - 
#pragma mark 微锦囊点击详情
//微锦囊点击详情
- (void)mguideButtonAction:(id)sender
{
    UIButton *button = (UIButton *)sender;
    MicroDetailViewController *micro = [[MicroDetailViewController alloc] init];
    micro.number = button.tag;
    [self.navigationController pushViewController:micro animated:YES];
    [micro release];
}

#pragma mark - 
#pragma mark 刷新
//上拉刷新 下拉加载(不用加载 这里就不需要加载方法了)
- (void)scrollView:(UIScrollView *)scrollView loadWithState:(LoadState)state
{
    if (state == PullDownLoadState) {
        [self performSelector:@selector(downLoad) withObject:nil afterDelay:2];
    }
}

- (void) downLoad
{
    [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self json];
    _table.canPullUp = YES;
    [_table stopLoadWithState:PullDownLoadState];
}

#pragma mark - 
#pragma mark 获得cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //获得文本的高度
    NSDictionary *mydic = [_tableArray objectAtIndex:indexPath.row];
    NSDictionary *dic  = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13.0f], NSFontAttributeName, nil];
    if (IOS_VERSION > 7.0) {
        CGRect rect = [[mydic objectForKey:@"text"] boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        CGFloat height = rect.size.height + SCREEN_HEIGHT*1/4 + 35;
        return height;
    } else {
        CGFloat height = [[mydic objectForKey:@"text"]sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(300, 1000)].height;
        return height + SCREEN_HEIGHT*1/4 + 35;
    }
}

#pragma mark - 
#pragma mark TabelDataSource代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_tableArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TravelTopicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"travelCell"];
    NSDictionary *dic = [_tableArray objectAtIndex:indexPath.row];

    //图片赋值
    [cell.cover sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"cover"]] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
    cell.text.text = [dic objectForKey:@"text"];
    return  cell;
}

#pragma mark - 
#pragma mark 身边人
- (void)aroundPeople : (ExtraButton *)button
{
    button.imageV.image = [UIImage imageNamed:@"iconfont-friendfill.png"];
    AroundPeopleViewControllers *around = [[AroundPeopleViewControllers alloc] init];
    
    [self presentViewController:around animated:NO completion:nil];
    [around release];
}

//我的
- (void)myLogin:(ExtraButton *)button
{
    button.imageV.image = [UIImage imageNamed:@"iconfont-favorfill.png"];
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    if ([[user objectForKey:@"login"] isEqualToString:@"yes"]) {
        sinaWiboViewController *sina = [[sinaWiboViewController alloc] init];
        UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:sina];
        [self presentViewController:na animated:YES completion:nil];
        [sina release];
        [na release];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"不好意思" message:@"请先登录哦~" delegate:self cancelButtonTitle:@"登陆" otherButtonTitles:@"取消", nil];
        alert.delegate = self;
        [alert show];
        [alert release];
    }
}

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        LoginViewCnntroller *login = [[LoginViewCnntroller alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
        [self presentViewController:nav animated:YES completion:nil];
        login.scroll.contentOffset = CGPointMake(login.scroll.frame.size.width, 0);
        [login release];
        [nav release];
    }
}

#pragma mark - 
#pragma mark 精图
//点击精图改变页面
- (void) beautyPicture :(id)sender
{
    Beauty_PicViewController *beauti = [[Beauty_PicViewController alloc] init];
    [self.navigationController pushViewController:beauti animated:YES];
    [beauti release];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
